<?php
/* @var $this AttModController */
/* @var $model AttMod */
/* @var $form CActiveForm */
$attributeTexttType = Attribute::model()->getTextType();
//准备下拉菜单字符串，为js调用做准备
$textTypeSelectStr1 = '<select class="s_ipt  w_120 mr20" name="';
$textTypeSelectStr2 = '" id="AttMod_spe_0">';
foreach($attributeTexttType as $key=>$val){
	$textTypeSelectStr2 .='<option value="'.$key.'">'.$val.'</option>';
}
$textTypeSelectStr2 .='</select>';
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'att-mod-form',
	'enableAjaxValidation'=>false,
	'enableClientValidation'=>true,
)); ?>
<ul class="form_list form_list2">

	<li class="c_f">
		<span class="tit">模型名称：</span>
		<div class="cont f_l">
			<?php echo $form->textField($model,'zmd_title',array('size'=>20,'maxlength'=>20,'class'=>'t_ipt ipt_bg w_250')); ?>
			<?php echo $form->error($model,'zmd_title')?>
		</div>
	</li>
	
	<li class="c_f">
		<span class="tit">规格：</span>
		<div class="cont f_l ">
			<?php if(!empty($model->zmd_spe)){ $spe = unserialize($model->zmd_spe) ?>
			<?php foreach($spe as $key1=>$val1){?>
				<p class="p_5">
					名称：<?php echo CHtml::textField('AttMod[zmd_spe]['.$key1.'][za_title]',$val1['za_title'],array('class'=>'t_ipt ipt_bg w_80 mr20'))?>
					控件类型：<?php echo CHtml::dropDownList('AttMod[zmd_spe]['.$key1.'][za_text_type]',$val1['za_text_type'],Attribute::model()->getTextType(),array('class'=>'s_ipt  w_120 mr20'))?>
					值：<?php echo CHtml::textField('AttMod[zmd_spe]['.$key1.'][za_value]',$val1['za_value'],array('class'=>'t_ipt ipt_bg w_250'))?>
				</p>
			<?php }}?>
			<p><?php echo CHtml::linkbtn('新建规格行','javascript:',array('class'=>'mem_bgx link_btn mr5','id'=>'addspe_button'))?></p>
		</div>
	</li>
	<li class="c_f">
		<span class="tit">属性：</span>
		<div class="cont f_l">
			<?php if(!empty($model->zmd_val)){ $val = unserialize($model->zmd_val) ?>
			<?php foreach($val as $key2=>$val2){?>
				<p class="p_5">
					名称：<?php echo CHtml::textField('AttMod[zmd_val]['.$key2.'][za_title]',$val2['za_title'],array('class'=>'t_ipt ipt_bg w_80 mr20'))?>
					控件类型：<?php echo CHtml::dropDownList('AttMod[zmd_val]['.$key2.'][za_text_type]',$val2['za_text_type'],Attribute::model()->getTextType(),array('class'=>'s_ipt  w_120 mr20'))?>
					值：<?php echo CHtml::textField('AttMod[zmd_val]['.$key2.'][za_value]',$val2['za_value'],array('class'=>'t_ipt ipt_bg w_250'))?>
				</p>
			<?php }}?>
			<p><?php echo CHtml::linkbtn('新建属性行','javascript:',array('class'=>'mem_bgx link_btn mr5','id'=>'addval_button'))?></p>
		</div>
	</li>
	<li class="c_f"><span class="tit">&nbsp;</span>
		<div class="cont f_l">
			<?php echo CHtml::submitButton(Yii::t('adm','Save Date'),array('class'=>'mem_btn mem_btn20 mr5')); ?>
		</div>
	</li>
</ul>

<?php $this->endWidget(); ?>

</div><!-- form -->

<script type="text/javascript">
var specount = <?php echo isset($key1)?$key1+1:0?>;
var valcount = <?php echo isset($key2)?$key2+1:0?>;

$('#addspe_button').bind('click',function(){
	if(specount==2){
		alert("规格只有允许两条");
		return;
	}
	var str = '<p class="p_5">名称：<input class="t_ipt ipt_bg w_80 mr20" type="text" value="" name="AttMod[zmd_spe]['+specount+'][za_title]" id="AttMod_spe_0">			控件类型：'
		+'<?php echo $textTypeSelectStr1 ?>'
		+'AttMod[zmd_spe]['+specount+'][za_text_type]'
		+'<?php echo $textTypeSelectStr2 ?>'
		+'			值：<input class="t_ipt ipt_bg w_250" type="text" value="" name="AttMod[zmd_spe]['+specount+'][za_value]" id="AttMod_spe_0">			</p>'
	$(this).before(str);
	specount++;
});

$('#addval_button').bind('click',function(){
	var str = '<p class="p_5">名称：<input class="t_ipt ipt_bg w_80 mr20" type="text" value="" name="AttMod[zmd_val]['+valcount+'][za_title]" id="AttMod_spe_0">			控件类型：'
		+'<?php echo $textTypeSelectStr1 ?>'
		+'AttMod[zmd_val]['+valcount+'][za_text_type]'
		+'<?php echo $textTypeSelectStr2 ?>'
		+'			值：<input class="t_ipt ipt_bg w_250" type="text" value="" name="AttMod[zmd_val]['+valcount+'][za_value]" id="AttMod_spe_0">			</p>'
	$(this).before(str);
	valcount++;
});

</script>